﻿using Andy.Web.SanPhamServiceReference;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Andy.Web.admin
{
    public partial class ht_sxsp : VdcInc.vdcAJAXPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadGridSapXep();
            }

        }
        public void loadGridSapXep()
        {
            using (var spService = new SanPhamServiceReference.SanPhamServiceClient())
            {
                var lst = spService.DanhSachViTriSanPham();
                if (lst != null)
                {
                    grid1.DataSource = lst;
                    grid1.DataBind();
                }
            }
        }
        public string saveRowPosition(string records)
        {

            char[] sep = { '|' };
            string[] rows = records.Split(sep);
            string resultCapNhat = "";
            List<SanPham> lst = new List<SanPham>();
            using (var spService = new SanPhamServiceReference.SanPhamServiceClient())
            {
                for (int i = 0; i < rows.Length - 1; i++)
                {
                    string row = rows[i];
                    char[] sep2 = { ',' };
                    string[] cells = row.Split(sep2);
                    SanPham sp = new SanPham();
                    sp.Id = Convert.ToInt64(cells[0]);
                    sp.ViTri = Convert.ToInt64(cells[1]);
                    lst.Add(sp);


                }
                resultCapNhat = spService.CapNhatViTriSanPham(lst);
                if (resultCapNhat == null) resultCapNhat = "Thất bại";
            }
            return resultCapNhat;
        }
    }
}